package com.fcgzs.springboot.controller;


import com.fcgzs.springboot.pojo.Setmeal;
import com.fcgzs.springboot.service.SetmealService;
import com.fcgzs.springboot.util.PageResult;
import com.fcgzs.springboot.util.QueryPageBean;
import com.fcgzs.springboot.util.Result;
import org.apache.dubbo.config.annotation.Reference;
//import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.File;
import java.io.IOException;
import java.util.UUID;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wjd
 * @since 2021-10-12
 */
@RestController
@RequestMapping("/setmeal")
public class SetmealController {

    @Reference
    private SetmealService setmealService;

//    @Resource
//    private RedisTemplate<String,String> redisTemplate;

    //MultipartFile是用来上传文件的java对象
    @RequestMapping("/uploadPic")
    public Result uploadPic(MultipartFile imgFile){
        String originalFilename = null;
        try {
            //指定文件存储的本地路径
            String path = "E:\\缓存区\\上传路径\\upload\\"; //路径少//
            //获取文件名称，uuid重新命名
            originalFilename = imgFile.getOriginalFilename();
            String s = UUID.randomUUID().toString();
            originalFilename = s+originalFilename;
            File file = new File(path+originalFilename);
            //上传文件
            imgFile.transferTo(file);
            //将上传的图片名加载到redis集合
//            redisTemplate.opsForSet().add("updloadpic",originalFilename);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new Result(true,"",originalFilename);
    }

    //添加套餐
    @RequestMapping("/addSetmealInfo")
    public Result addSetmealInfo(@RequestBody Setmeal setmeal,Integer [] ids){
        //将上传的图片名加载到redis集合
//        redisTemplate.opsForSet().add("dbpic",setmeal.getImg());
        return setmealService.addSetmealInfo(setmeal,ids);
    }

    //分页方法
    @RequestMapping("/querySetmealPageInfo")
    public PageResult querySetmealPageInfo(@RequestBody QueryPageBean queryPageBean,Integer mark){
        return setmealService.querySetmealPageInfo(queryPageBean,mark);
    }

    //删除套餐
    @RequestMapping("/deleteSetmealInfo")
    public Result deleteSetmealInfo(Integer id){
        return setmealService.deleteSetmealInfo(id);
    }

    //获取套餐
    @RequestMapping("/getOneSetmealById")
    public Result getOneSetmealById(Integer id){
        return setmealService.getOneSetmealById(id);
    }

}

